package com.controller;

import com.common.Result;
import com.pojo.dto.OrderDto;
import com.pojo.dto.OrderGoodsDto;
import com.pojo.dto.OrdersDto;
import com.pojo.entity.Orders;
import com.service.IOrderGoodsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 杨世博
 * @date: Created in 15:50 2023/6/4
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单接口")
@Slf4j
public class OrderGoodsController {

    @Autowired
    IOrderGoodsService orderGoodsService;

    /**
     * 提交订单
     * @param orderGoodsDto
     * @return
     */
    @PostMapping("/submitOrder")
    public Result<OrderDto> submitOrder(@RequestBody OrderGoodsDto orderGoodsDto){
        OrderDto orderGoods = orderGoodsService.submitOrder(orderGoodsDto);
        return Result.success(orderGoods);
    }

    @PostMapping("/payOrder")
    public Result<Boolean> payOrder(@RequestParam("orderId")Integer orderId){
        orderGoodsService.payOrder(orderId);
        return Result.success();
    }

    @PostMapping("/cancelOrder")
    public Result<Boolean> cancelOrder(@RequestParam("id")Integer id){
        Boolean aBoolean = orderGoodsService.deleteOrder(id);
        return Result.success();
    }

    /**
     * 获取待收货
     * @param uid
     * @return
     */
    @PostMapping("/getLogistics")
    public Result<List<OrdersDto>> getLogistics(@RequestParam("uid")Integer uid){
        return Result.success(orderGoodsService.getLogistics(uid));
    }


    /**
     * 退款
     * @param orderId
     * @return
     */
    @PostMapping("/refund")
    public Result<Boolean> refund(@RequestParam("orderId")Integer orderId){
        return Result.success(orderGoodsService.refund(orderId));
    }

    /**
     * 确认收款
     * @return
     */
    @PostMapping("/confirmReceipt")
    public Result<Boolean> confirmReceipt(@RequestParam("orderId")Integer orderId){
        return Result.success(orderGoodsService.confirmReceipt(orderId));
    }

    /**
     * 查找个人全部订单
     * @param uid
     * @return
     */
    @PostMapping("/findPersonAllOrder")
    public Result<List<OrdersDto>> findPersonAllOrder(@RequestParam("uid")Integer uid){
        return Result.success(orderGoodsService.findPersonAllOrder(uid));
    }

    /**
     * 查看个人未提交订单
     * @param uid
     * @return
     */
    @PostMapping("/findPersonNotPaidOrder")
    public Result<List<OrdersDto>> findPersonNotPaidOrder(@RequestParam("uid")Integer uid){
        return Result.success(orderGoodsService.findPersonNotPaidOrder(uid));
    }

    @PostMapping("/findPersonPaidOrder")
    public Result<List<OrdersDto>> findPersonPaidOrder(@RequestParam("uid")Integer uid){
        return Result.success(orderGoodsService.findPersonPaidOrder(uid));
    }

    /**
     * 商家查询全部订单
     * @param merchantId
     * @return
     */
    @PostMapping("/findShopAllOrder")
    public Result<List<OrdersDto>> findShopAllOrder(@RequestParam("merchantId")Integer merchantId){
        return Result.success(orderGoodsService.findShopAllOrder(merchantId));
    }

    /**
     * 商家查询未付款订单
     * @param merchantId
     * @return
     */
    @PostMapping("/findShopNotPaidOrder")
    public Result<List<OrdersDto>> findShopNotPaidOrder(@RequestParam("merchantId")Integer merchantId){
        return Result.success(orderGoodsService.findShopNotPaidOrder(merchantId));
    }

    /**
     * 商家查询退款订单
     * @param merchantId
     * @return
     */
    @PostMapping("/findShopRefundOrder")
    public Result<List<OrdersDto>> findShopRefundOrder(@RequestParam("merchantId")Integer merchantId){
        return Result.success(orderGoodsService.findShopRefundOrder(merchantId));
    }

    /**
     * 处理退款
     * @param orderId
     * @return
     */
    @PostMapping("/dealWithRefund")
    public Result<Boolean> dealWithRefund(@RequestParam("orderId")Integer orderId){
        orderGoodsService.dealWithRefund(orderId);
        return Result.success();
    }


    /**
     * 商家发货
     * @param expressNo
     * @param expressName
     * @param orderId
     * @return
     */
    @PostMapping("/deliverGoods")
    public Result<Boolean> deliverGoods(@RequestParam("expressNo")Integer expressNo,
                                        @RequestParam("expressName")String expressName,
                                        @RequestParam("orderId")Integer orderId){
        orderGoodsService.deliverGoods(expressNo, expressName, orderId);
        return Result.success();
    }

    @PostMapping("/getShopDeliverOrder")
    public Result<List<OrdersDto>> getShopDeliverOrder(@RequestParam("merchantId")Integer merchantId){
        List<OrdersDto> ordersDto = orderGoodsService.getShopDeliverOrder(merchantId);

        return Result.success(ordersDto);
    }
}
